[Coding044] LeetCode 150

Evaluate Reverse Polish Notation

Cook 2024.04.12

More coding records

Get the knowledge flowing and circulating! :)

目录

本题收获

题目:150. Evaluate Reverse Polish Notation

You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.

Evaluate the expression. Return an integer that represents the value of the expression.

Note that:

Example 1:

Example 2:

Example 3:

Constraints:


代码1(配 · 手绘过程图)

image-20240412115035262

代码解读 | 评价

思路清晰之后,写出来的代码就比较可观了!

  • op1 - op2

  • op1 / op2

注意顺序:栈中弹出的第一数是op2, 第2个数是op1。这个对于加法、乘法没有影响,但是对于减法和除法有影响。

 


代码2(以前写的代码)

代码解读 | 评价

  • 以前写的代码似乎看上去有点复杂呢~


 

知识点积累 (Java)

// 问题1: 怎样把字符串“12”变成int型呢?

// // 问题2:怎样对比两个字符串呢?